#include "resource.h"
#include <QDebug>

Resource::Resource(int parentId,String rName,bool use)
{
    pID = parentId;
    inUse = use;
    name = rName;
    resID = ResourceAllocator::getSingleton().giveNextResourceId();

    elementas = new ElementsBase();

}
Resource::~Resource() {
    delete(elementas);
}

void Resource::addToWaitingList(int waitingId)
{
    //qDebug() << "Pridejo i laukianciu sarasa" << waitingId;
    waitingList.push_back(waitingId);

}
void Resource::removeFromWaitingList(){
    if(waitingList.size() > 0) {
        waitingList.erase(waitingList.begin());
    }else {
        qDebug() << "waiting list empty @ Resource::removeFromWaitingList";
    }

}
ElementsBase* Resource::getElement(){
    return(elementas);
}
int Resource::getFreeElements() {
    int ret=0;
    if (name == "UserMemory") {
        for (ElementsIterator it = elementas->begin(); it != elementas->end(); ++it) {
            if ((*it )=="t") {
               ret++;
            }
        };
    } else {
        if (inUse)
            {ret = 0;}
            else {ret=1;};
    }
    return(ret);
}
